function testPrint(flag, pix) {
    if (flag) {
        console.log(pix, " 测试成功...")
    } else {
        console.log(pix, " 测试失败...")
    }
}

/**
 * 测试添加，扩容
 */
function arrayListTestCase01() {
    let a = new ArrayList(2);
    a.add('A')
    a.add('B')
    let result = a.size == 2 && a.capacity == 2;
    testPrint(result, "arrayListTestCase01")
    a.add('C')
    result = a.size == 3 && a.capacity == 4;
    testPrint(result, "arrayListTestCase01")

    let ex = ['A', 'B', 'C'];
    result = eqArray(ex, a.store)
    testPrint(result, "arrayListTestCase01")
}

arrayListTestCase01();

function arrayListTestCase02() {
    let a = new ArrayList(2);
    a.add('A')
    a.add('B')
    a.add('C')
    a.add('D')
    a.addByIndex(2, '1')
    let ex = ['A', 'B', '1', 'C', 'D'];
    let result = eqArray(ex, a.store)
    testPrint(result, "arrayListTestCase02")

    a.updateByIndex(0, 'AA')
    ex = ['AA', 'B', '1', 'C', 'D'];
    result = eqArray(ex, a.store)
    testPrint(result, "arrayListTestCase02")


    a.remove(3)
    ex = ['AA', 'B', '1', 'D'];
    result = eqArray(ex, a.store)
    testPrint(result, "arrayListTestCase02")
}
arrayListTestCase02();

function arrayListTestCase03() {
    let a = new ArrayList(2);
    a.add('A')
    a.add('B')
    a.add('C')
    a.add('D')
    a.add('B')
    a.removeEle('B')
    let ex = ['A', 'C', 'D', 'B'];
    let result = eqArray(ex, a.store)
    testPrint(result, "arrayListTestCase03")

    a.removeEle('B')
    ex = ['A', 'C', 'D'];
    result = eqArray(ex, a.store)
    testPrint(result, "arrayListTestCase03")
}

arrayListTestCase03();

function arrayListTestCase04() {
    let a = new ArrayList(2);
    let result = 0;
    try {
        a.getEleByIndex(0);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "arrayListTestCase04")
    }
    try {
        a.updateByIndex(0, 'A')
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "arrayListTestCase04")
    }
    try {
        a.remove(0);
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "arrayListTestCase04")
    }
}
arrayListTestCase04();

function fixedArrayTestCase01() {
    let a = new FixedArray(2);
    a.add('A')
    a.add('B')
    let ex = ['A', 'B'];
    let result = eqArray(ex, a.store)
    testPrint(result, "fixedArrayTestCase01")

    try {
        a.add('C')
    } catch (e) {
        result = eqStr(e.message, '超出数组的范围')
        testPrint(result, "fixedArrayTestCase01")
    }
}
fixedArrayTestCase01();



function fixedArrayTestCase02() {
    let a = new FixedArray(2);
    a.add('A')
    a.add('B')
    a.remove(1)
    let ex = ['A'];
    let result = eqArray(ex, a.store)
    testPrint(result, "fixedArrayTestCase02")
    a.remove(0)
    try {
        a.remove(0)
    } catch (e) {
        result = eqStr(e.message, '超出数组范围')
        testPrint(result, "fixedArrayTestCase02")
    }
}

fixedArrayTestCase02();